<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            position: absolute;
            left: 0px;
            top:0px;
        }
        .menu{
            width: 100px;
            height: 200px;
            background: blue;
            position: absolute;
            display: none;
        }
    </style>
</head>
<body>
    <div class="box">x:100px;y:100px</div>
    <div class="menu"></div>
    <script>
        // 一个坐标跟随鼠标 1.事件 2.获取坐标
        var boxEle = document.querySelector(".box");
        document.onmousemove = function(e){
            var x = e.clientX;
            var y = e.clientY;
            console.log(x,y);
            boxEle.style.left = x + "px";
            boxEle.style.top = y + "px";
            boxEle.innerHTML = `x:${x}px;y:${y}px`;
        }
        var menuEle = document.querySelector(".menu");
        document.oncontextmenu = function(e){
            // 获取点击右键时候的鼠标坐标
            var x = e.clientX;
            var y = e.clientY;
            menuEle.style.display = "block";
            menuEle.style.left = x + "px";
            menuEle.style.top = y + "px";
            e.preventDefault();
        }
        document.onclick = function(){
            menuEle.style.display = "none";
        }

        // 


    </script>
</body>
</html>